package com.example.d3.character.compare;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class HeroDataAdapter extends BaseAdapter {
	private Context context;
	private HeroData[] heroList;
	
	public HeroDataAdapter(Context context, HeroData[] hdList) {
		this.context = context;
		this.heroList = hdList;
	}
	
	public int getCount() {
		return heroList.length;
	}

	public Object getItem(int pos){
		return heroList[pos];
	}
	
	public long getItemId(int pos){
		return pos;
	}
	
	public View getView(int pos, View convertView, ViewGroup viewGroup){
		HeroData hd = heroList[pos];
		
		if(convertView == null) {
			LayoutInflater infl = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = infl.inflate(R.layout.character_item, null);
		}
		((TextView)convertView.findViewById(R.id.hero)).setText(hd.name());
		((TextView)convertView.findViewById(R.id.tvLevel)).setText(Integer.toString(hd.level()));
		((TextView)convertView.findViewById(R.id.tvClassName)).setText(hd.className());
		
		return convertView;
	}
}
